package com.hashbee.bbs.controller;

import com.hashbee.bbs.bo.PageData;
import com.hashbee.bbs.bo.para.PageQueryPara;
import com.hashbee.bbs.domain.Notification;
import com.hashbee.bbs.service.NotificationService;
import com.hashbee.bo.ReturnData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bbs/notification")
public class NotificationController {

    private static final Logger logger = LoggerFactory.getLogger(NotificationController.class);

    @Autowired
    private NotificationService notificationService;

    @GetMapping("/page")
    public ReturnData<PageData<Notification>> page(@RequestParam(value = "pageIndex", required = false, defaultValue = "0") Integer pageIndex,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {

        PageQueryPara pageQueryPara = new PageQueryPara();
        pageQueryPara.setPageIndex(pageIndex);
        pageQueryPara.setPageSize(pageSize);

        return notificationService.queryPage(pageQueryPara);
    }

    @GetMapping("/detail")
    public ReturnData<Notification> detail(@RequestParam(value = "notificationId", required = true) Integer notificationId) {
        PageQueryPara pageQueryPara = new PageQueryPara();
        pageQueryPara.setNotificationId(notificationId);

        return notificationService.queryDetail(pageQueryPara);
    }

    @PostMapping("/read")
    public ReturnData read(@RequestParam(value = "notificationIds", required = true) String notificationIds) {

        ReturnData returnData = new ReturnData();
        notificationService.read(notificationIds);
        return returnData;
    }

    @GetMapping("/unread/count")
    public ReturnData<Integer> unread() {
        return notificationService.unread();
    }
}
